<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
  <style>
    .active {
      background-color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <div>
      <button v-for="item in 5" :class="{active:pageInfo.currentPage===item}"
        @click="pageInfo.currentPage=item">{{item}}</button>
      <select v-model="pageInfo.limit">
        <option value="3">每页3条</option>
        <option value="6">每页6条</option>
        <option value="9">每页9条</option>
        <option value="12">每页12条</option>

      </select>
    </div>
  </div>
  <script>
    // 一定要侦听数据 如果目的是得到一个值 则选择计算属性 其他就选择watch(计算属性能做的watch都可以做到 但是watch能做的计算属性不一定)
    new Vue({
      el: "#app",
      data() {
        return {
          pageInfo: {
            // 当前页是1
            currentPage: 1,
            // 每页条数是3
            limit: 3
          }
        };
      },
      methods: {
        // 获取数据的函数
        getData(page, limit) {
          console.log(`重新获取数据,当前页是${page},每页条数是${limit}`);
        }
      },
      watch: {
        //  如果想要监听某个对象内部的属性 则需要使用字符串的格式
        "pageInfo.currentPage": {
          immediate: true,
          handler(newVal, oldVal) {
            console.log(newVal, oldVal);
            this.getData(newVal, this.pageInfo.limit);
          }
        },
        "pageInfo.limit": {
          immediate: true,
          handler(newVal, oldVal) {
            console.log(newVal, oldVal);
            this.getData(this.pageInfo.currentPage, newVal);
          }
        },
      }
    })
  </script>
</body>

</html>